﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Facebook;

namespace FBEventMaker
{
    public partial class ViewWallPost : PhoneApplicationPage
    {
        private string m_AccessToken;

        public ViewWallPost()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            m_AccessToken = NavigationContext.QueryString["access_token"];

        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            FacebookClient fb = new FacebookClient(m_AccessToken);
           
            #region define service routine
            fb.GetCompleted += (o, args) =>
            {
                if (args.Error == null)
                {
                    var retVal = (IList<object>)args.GetResultData();
                    Dispatcher.BeginInvoke(() => m_WallListBox.ItemsSource = WallPostDataResources.createDataResources(retVal));
                }
                else
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show(args.Error.Message));
                }
            };
            #endregion

            // call the Query or QueryAsync method to execute a single fql query.
            fb.QueryAsync(WallPostDataResources.FqlQuery);
        }
    }
}